//
//  ScoreFGoodsDetailsViewController.m
//  HongFuShop
//
//  Created by chirui on 2017/8/31.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "ScoreFGoodsDetailsViewController.h"

@interface ScoreFGoodsDetailsViewController ()

@property (nonatomic, strong) UIWebView *webView;

@end

@implementation ScoreFGoodsDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.view.backgroundColor =[UIColor whiteColor];
    
    self.navigationItem.titleView = [TopLabel withLabelWithLabelText:@"商品详情"];
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"icon_public_return" target:self action:@selector(backButton)];
    
    UIButton * sumBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [sumBtn setBackgroundImage:ImageName(@"img_home_nav_bg") forState:UIControlStateNormal];
    [sumBtn setTitle:@"立即兑换" forState:UIControlStateNormal];
    sumBtn.frame = CGRectMake(60,HEIGHT-48-15 , WIDTH-120, 45);
    sumBtn.layer.cornerRadius= 22.5f;
    sumBtn.layer.masksToBounds = YES;
    [sumBtn addTarget:self action:@selector(sumBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:sumBtn];

    
    [self creatWebWith:self.urlStr];
}

-(void)sumBtnClick{

    [self getGoodsDetailsRequest];
    
}

-(void)backButton{
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)creatWebWith:(NSString *)str {
    
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,64,WIDTH, HEIGHT-80-64)];
    _webView.scalesPageToFit = YES;
    
    NSURL* url =[NSURL URLWithString:str];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [_webView loadRequest:request];
    
    [self.view addSubview:self.webView];
    
}

-(void)getGoodsDetailsRequest{
    
    NSDictionary * dic = @{@"user_id":USER_DEFAULTGet(@"user_id"),
                           @"token":USER_DEFAULTGet(@"token"),
                           @"goods_id":self.goods_id};
    SHuiMBhubNoTimeLoding;
    [PostNetWorking postNetWorkingStr:RequestUrlStr(score_exchangeGoods_api) andparameters:dic Success:^(id responseObject) {
        SHuiMBHidleYes;
        if (codeSucess) {
           
            SHuiMBhudTextTimeStr(@"兑换成功！");
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                [self.navigationController popViewControllerAnimated:YES];
            });
            
        }else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
    } failed:^(NSError *error) {
        SHuiMBHidleYes;
        SHuiMBhudTextNetError;
    }];
    
}


@end
